----------------------------------------------------------------------------------------------------------------------------------
--[[

    血梅香

    remain time  ：留存时间
    damage time  : 伤害时间

]]--
----------------------------------------------------------------------------------------------------------------------------------
--
    local function GetReplica(self)
        return self.inst.replica.hutao_com_blood_plum_scent_for_debuff or self.inst.replica._.hutao_com_blood_plum_scent_for_debuff
    end
    local function set_remain_time(self, time)
        local replica = GetReplica(self)
        if replica then
            replica:SetRemainTime(time)
        end
    end
    local function set_damage_time(self, time)
        local replica = GetReplica(self)
        if replica then
            replica:SetDamageTime(time)
        end
    end
    local function set_damage_time_scale(self,param)
        local replica = GetReplica(self)
        if replica then
            replica:SetDamageTimeScale(param)
        end
    end
    local function set_player(self, player)
        local replica = GetReplica(self)
        if replica then
            replica:SetPlayer(player)
        end
    end
    local function set_target(self, target)
        local replica = GetReplica(self)
        if replica then
            replica:SetTarget(target)
        end
    end
----------------------------------------------------------------------------------------------------------------------------------
--
    local DEBUFF_REFRESH_TIME = 0.05
----------------------------------------------------------------------------------------------------------------------------------
local hutao_com_blood_plum_scent_for_debuff = Class(function(self, inst)
    self.inst = inst



    self.remain_time = 10
    self.damage_time = 6

    self.remain_time_base = 10
    self.damage_time_base = 6

    self.damage_hit = 1 -- 伤害次数

    inst:DoPeriodicTask(DEBUFF_REFRESH_TIME,function()
        self:Update()
    end)

    self.player = nil
    self.target = nil

    self.damage_time_scale = self.damage_time / self.damage_time_base

end,
nil,
{
    remain_time = set_remain_time,
    damage_time = set_damage_time,
    damage_time_scale = set_damage_time_scale,
    player = set_player,
    target = set_target
})
------------------------------------------------------------------------------------------------------------------------------
--
    function hutao_com_blood_plum_scent_for_debuff:SetRemainTime(time)
        self.remain_time = time
    end
    function hutao_com_blood_plum_scent_for_debuff:GetRemainTime()
        return self.remain_time
    end
    function hutao_com_blood_plum_scent_for_debuff:SetRemainTimeBase(time)
        self.remain_time_base = time
    end
    function hutao_com_blood_plum_scent_for_debuff:ResetRemainTime()    -- 重置时间
        self.remain_time = self.remain_time_base
    end
    function hutao_com_blood_plum_scent_for_debuff:SetDamageTime(time)
        self.damage_time = time
    end
    function hutao_com_blood_plum_scent_for_debuff:GetDamageTime()
        return self.damage_time
    end
    function hutao_com_blood_plum_scent_for_debuff:SetDamageTimeBase(time)  
        self.damage_time_base = time
    end
    function hutao_com_blood_plum_scent_for_debuff:ResetDamageTime()    -- 重置时间
        self.damage_time = self.damage_time_base
    end
------------------------------------------------------------------------------------------------------------------------------
-- player / target
    function hutao_com_blood_plum_scent_for_debuff:SetPlayer(player)
        self.player = player
    end
    function hutao_com_blood_plum_scent_for_debuff:SetTarget(target)
        self.target = target
    end
------------------------------------------------------------------------------------------------------------------------------
-- 
    function hutao_com_blood_plum_scent_for_debuff:SetDamageFn(fn)
        self.damage_fn = fn
    end
    function hutao_com_blood_plum_scent_for_debuff:DoDamage()
        if self.damage_fn then
            self.damage_fn(self.inst,self.player, self.target,self.damage_hit)
        end
        self.player:PushEvent("hutao_com_blood_plum_scent_for_debuff.damage",{
            target = self.target,
            hit = self.damage_hit,
        })
    end
------------------------------------------------------------------------------------------------------------------------------
-- 更新函数
    function hutao_com_blood_plum_scent_for_debuff:Update()
        -----------------------------------------------------
        --- 玩家绑定检查
            if ( self.player == nil or not self.player:IsValid() ) or (self.target == nil or not self.target:IsValid()) then
                self.inst:Remove()
                return
            end
        -----------------------------------------------------
        ---
            if self.target.components.health:IsDead() then
                self.inst:Remove()
                return
            end
        -----------------------------------------------------
        --- debuff 留存时间
            self.remain_time = self.remain_time - DEBUFF_REFRESH_TIME
            if self.remain_time <= 0 then
                self.inst:Remove()
                return
            end
        -----------------------------------------------------
        --- debuff 伤害时间
            self.damage_time = self.damage_time - DEBUFF_REFRESH_TIME
            if self.damage_time <= 0 then
                self:DoDamage()
                self.damage_time = self.damage_time_base
                self.damage_hit = self.damage_hit + 1
            end
        -----------------------------------------------------
        ---
            self.damage_time_scale = self.damage_time / self.damage_time_base
        -----------------------------------------------------
    end
------------------------------------------------------------------------------------------------------------------------------
return hutao_com_blood_plum_scent_for_debuff







